home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / macintosh-c / macc-carbon-demos-nonbinhex.sit / macc-carbon-demos-nonbinhex / chap18-demo-classic events / Files.h < prev    next >
Text File  |  2001-06-05  |  8KB  |  181 lines

  1. // *******************************************************************************************
  2. // Files.h                                                                 CLASSIC EVENT MODEL
  3. // *******************************************************************************************
  4. //
  5. // This program demonstrates:
  6. //
  7. // •    File operations associated with:
  8. //
  9. //        •    The user invoking the File menu Open…, Close, Save, Save As…, Revert, and Quit
  10. //            commands of a typical application.
  11. //
  12. //        •    Handling of the required Apple events Open Application, Re-open Application, Open
  13. //            Documents, Print Documents, and Quit Application.
  14. //
  15. // •    File synchronisation.
  16. //
  17. // •    The creation, display, and handling of Open, Save Location, Choose a Folder, Save
  18. //        Changes and Discard Changes dialogs and alerts using the new model introduced with
  19. //        Navigation Services 3.0.
  20. //
  21. // To keep the code not specifically related to files and file-handling to a minimum, an item 
  22. // is included in the Demonstration menu which allows the user to simulate "touching" a window
  23. // (that is, modifying the contents of the associated document).  Choosing the first menu item
  24. // in this menu sets the window-touched flag in the window's document structure to true and
  25. // draws the text "WINDOW TOUCHED" in the window in a large font size, this latter so that the
  26. // user can keep track of which windows have been "touched".
  27. //
  28. // This program is also, in part, an extension of the demonstration program Windows2 in that
  29. // it also demonstrates certain file-related Window Manager features introduced with the Mac
  30. // OS 8.5 Window Manager.  These features are:
  31. //
  32. // •    Window proxy icons.
  33. //
  34. // •    Window path pop-up menus.
  35. //
  36. // Those sections of the source code relating to these features are identified with ///// at
  37. // the right of each line.
  38. //
  39. // The program utilises the following resources:
  40. //
  41. // •    A 'plst' resource.
  42. //
  43. // •    An 'MBAR' resource, and 'MENU' and 'xmnu' resources for Apple, File, Edit and 
  44. //        Demonstration menus (preload, non-purgeable).  
  45. //
  46. // •    A 'WIND' resource (purgeable) (initially not visible).  
  47. //
  48. // •    A 'STR ' resource containing the "missing application name" string, which is copied to
  49. //        all document files created by the program.
  50. //
  51. // •    'STR#' resources (purgeable) containing error strings, the application's name (for
  52. //        certain Navigation Services functions), and a message    string for the Choose a Folder
  53. //        dialog.
  54. //
  55. // •    An 'open' resource (purgeable) containing the file type list for the Open dialog.
  56. //
  57. // •    A 'kind' resource (purgeable) describing file types, which is used by Navigation 
  58. //        Services to  build the native file types section of the Show pop-up menu in the Open
  59. //        dialog.
  60. //
  61. // •    Two 'pnot' resources (purgeable) which, together with an associated 'PICT' resource 
  62. //        (purgeable) and a 'TEXT' resource created by the program, provide the previews for
  63. //        the PICT and, on Mac OS 8/9, TEXT files.
  64. //
  65. // •    The 'BNDL' resource (non-purgeable), 'FREF' resources (non-purgeable), signature
  66. //        resource (non-purgeable), and icon family resources (purgeable), required to support the
  67. //        built application on Mac OS 8/9.
  68. //
  69. // •    A 'SIZE' resource with the acceptSuspendResumeEvents, canBackground, 
  70. //        doesActivateOnFGSwitch, and isHighLevelEventAware flags set.
  71. //
  72. // *******************************************************************************************
  73.  
  74. // ………………………………………………………………………………………………………………………………………………………………………………………………………………………… includes
  75.  
  76. #include <Carbon.h>
  77.  
  78. // …………………………………………………………………………………………………………………………………………………………………………………………………………………………… defines
  79.  
  80. #define rMenubar                                    128
  81. #define mAppleApplication                    128
  82. #define  iAbout                                        1
  83. #define mFile                                            129
  84. #define  File_New                                    'new '
  85. #define  File_Open                                'open'
  86. #define  File_Close                                'clos'
  87. #define  File_Save                                'save'
  88. #define  File_SaveAs                            'sava'
  89. #define  File_Revert                            'reve'
  90. #define  File_Quit                                'quit'
  91. #define  iQuit                                        12
  92. #define mDemonstration                        131
  93. #define  Demo_TouchWindow                    'touc'
  94. #define  Demo_ChooseAFolderDialog    'choo'
  95. #define rNewWindow                                128
  96. #define rErrorStrings                            128    
  97. #define  eInstallHandler                    1000
  98. #define  eMaxWindows                            1001
  99. #define  eCantFindFinderProcess        1002                                                                                                     /////
  100. #define rMiscStrings                            129
  101. #define  sApplicationName                    1
  102. #define  sChooseAFolder                        2
  103. #define rOpenResource                            128
  104. #define kFileCreator                            'kJbb'
  105. #define kFileTypeTEXT                            'TEXT'
  106. #define kFileTypePICT                            'PICT'
  107. #define kMaxWindows                                10
  108. #define kOpen                                            0
  109. #define kPrint                                        1
  110. #define MIN(a,b)                                     ((a) < (b) ? (a) : (b))
  111.  
  112. // ………………………………………………………………………………………………………………………………………………………………………………………………………………………… typedefs
  113.  
  114. typedef struct
  115. {
  116.     TEHandle            editStrucHdl;
  117.     PicHandle            pictureHdl;
  118.     SInt16                fileRefNum;
  119.     FSSpec                fileFSSpec;
  120.     AliasHandle        aliasHdl;
  121.     Boolean                windowTouched;
  122.     NavDialogRef    modalToWindowNavDialogRef;
  123.     NavEventUPP        askSaveDiscardEventFunctionUPP;
  124.     Boolean                isAskSaveChangesDialog;
  125. }    docStructure, *docStructurePointer, **docStructureHandle;
  126.  
  127. // …………………………………………………………………………………………………………………………………………………………………………………………… function prototypes
  128.  
  129. void        main                                                    (void);
  130. void        eventLoop                                            (void);
  131. void        doPreliminaries                                (void);
  132. void        doInstallAEHandlers                        (void);
  133. void        doEvents                                            (EventRecord *);
  134. void        doMouseDown                                        (EventRecord *);
  135. void        doBringFinderToFront                    (void);                                                                                         /////
  136. OSErr        doFindProcess                                    (OSType,OSType,ProcessSerialNumber *);                         /////
  137. void        doUpdate                                            (EventRecord *);
  138. void        doMenuChoice                                    (SInt32);
  139. void        doCommand                                            (MenuCommand);
  140. void        doAdjustMenus                                    (void);
  141. void        doErrorAlert                                    (SInt16);
  142. void        doCopyPString                                    (Str255,Str255);
  143. void        doConcatPStrings                            (Str255,Str255);
  144. void        doTouchWindow                                    (void);
  145. OSErr        openAppEventHandler                        (AppleEvent *,AppleEvent *,SInt32);
  146. OSErr        reopenAppEventHandler                    (AppleEvent *,AppleEvent *,SInt32);
  147. OSErr        openAndPrintDocsEventHandler    (AppleEvent *,AppleEvent *,SInt32);
  148. OSErr        quitAppEventHandler                         (AppleEvent *,AppleEvent *,SInt32);
  149. OSErr        doHasGotRequiredParams                (AppleEvent *);
  150. SInt16    doReviewChangesAlert                    (SInt16);
  151.  
  152. OSErr     doNewCommand                                    (void);
  153. OSErr     doOpenCommand                                    (void);
  154. OSErr     doCloseCommand                                (NavAskSaveChangesAction);
  155. OSErr        doSaveCommand                                    (void);
  156. OSErr        doSaveAsCommand                                (void);
  157. OSErr        doRevertCommand                                (void);
  158.  
  159. OSErr        doNewDocWindow                                (Boolean,OSType,WindowRef *);
  160. OSErr     doCloseDocWindow                            (WindowRef);
  161. OSErr        doOpenFile                                        (FSSpec,OSType);
  162. OSErr        doReadTextFile                                (WindowRef);
  163. OSErr        doReadPictFile                                (WindowRef);
  164. OSErr     doCreateAskSaveChangesDialog    (WindowRef,docStructureHandle,NavAskSaveChangesAction);
  165. OSErr     doSaveUsingFSSpec                            (WindowRef,NavReplyRecord *);
  166. OSErr        doSaveUsingFSRef                            (WindowRef,NavReplyRecord *);
  167. OSErr        doWriteFile                                        (WindowRef);
  168. OSErr        doWriteTextData                                (WindowRef,SInt16);
  169. OSErr        doWritePictData                                (WindowRef,SInt16);
  170.  
  171. void        getFilePutFileEventFunction    (NavEventCallbackMessage,NavCBRecPtr,NavCallBackUserData);
  172. void      askSaveDiscardEventFunction    (NavEventCallbackMessage,NavCBRecPtr,NavCallBackUserData);
  173.  
  174. OSErr        doCopyResources                                (WindowRef);
  175. OSErr        doCopyAResource                                (ResType,SInt16,SInt16,SInt16);
  176.  
  177. void        doSynchroniseFiles                        (void);
  178. OSErr        doChooseAFolderDialog                    (void);
  179.  
  180. // *******************************************************************************************
  181.